package net.zjitc;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class TriMat {
    private int row;
    private int col;
    private int count;//记录非0个数
    private List<test1> list;

    public TriMat() {
        list=new ArrayList<>();
    }

    public void createTriple(int[][] arr){

        row=arr.length;
        col=arr[0].length;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                if (arr[i][j]!=0){
                    list.add(new test1(i,j,arr[i][j]));
                    count++;
                }
            }
        }
    }

    public int getRow() {
        return row;
    }

    public void setRow(int row) {
        this.row = row;
    }

    public int getCol() {
        return col;
    }

    public void setCol(int col) {
        this.col = col;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public List<test1> getList() {
        return list;
    }

    public void setList(List<test1> list) {
        this.list = list;
    }

    public int[][] decompression(){
        int[][] temp=new int[row][col];


          //迭代
        Iterator<test1> iterator=list.iterator();
        while (iterator.hasNext()){
           test1  test1=iterator.next();
           temp[test1.getRow()][test1.getCol()]=test1.getValue();
        }
        return temp;
    }
}
